const Koa = require("koa");
const Router = require("koa-router");
const static = require("koa-static");
const views = require("koa-views");
const router = require("./routers/router");
const { join } = require("path");
const body =require("koa-body");
const session = require("koa-session");
const logger = require("koa-logger");   //日志模块

//生成koa实例
const app = new Koa();

//注册日志模块
app.use(logger());

//配置koa-body处理post请求数据
app.use(body());

//session配置对象
app.keys = ['some secret hurr'];
const CONFIG = {
  key:"Sid",  //session id
  maxAge:36e5,
  overwrite:true,
  httpOnly:true,
  signed:true,
  rolling:false,
  renew:false
};

//配置session模块
app.use(session(CONFIG,app));

//配置静态资源目录
app.use(static(join(__dirname,"public")));

//配置视图模板
app.use(views(join(__dirname,"views"),{
    extension:"pug"
}));

//注册路由信息
app.use(router.routes()).use(router.allowedMethods());

//监听端口
app.listen(3000,()=>{
    console.log("项目启动成功，监听在3000端口");
});

